package main

import "fmt"

func main(){
    // 切片相关操作
    var numbers []int

    fmt.Println("Slice Append : ")
    printSlice("numbers : ", numbers)

    // 单元素append
    numbers = append(numbers, 0)
    printSlice("numbers : ", numbers)

    // 多元素append
    numbers = append(numbers, 1, 2, 3, 4, 5, 6, 7)
    printSlice("numbers : ", numbers)

    // 切片append进切片
    s1 := []int{1, 2, 3, 4, 5, 6}
    numbers = append(numbers, s1...)
    printSlice("numbers : ", numbers)

    fmt.Println("Slice Delete : ")

    // 删除第一个元素
    numbers = numbers[1:]
    printSlice("numbers : ", numbers)

    // 删除最后一个元素
    numbers = numbers[:len(numbers) - 1]
    printSlice("numbers : ", numbers)

    // 删除中间元素
    a := int(len(numbers) / 2)
    fmt.Println("中间下标 : ", a)
    fmt.Println("中间值 : ", numbers[a])
    numbers = append(numbers[:a], numbers[a+1:]...)
    printSlice("numbers : ", numbers)
}

// 打印 slice
func printSlice(name string, x []int)  {
    fmt.Print(name, "\t")
    fmt.Printf("Address : %p \t len=%d \t cap=%d \t value=%v \n", x, len(x), cap(x), x)
}
